package org.fu.crowd.controller;

import org.fu.crowd.service.api.OrderService;
import org.fu.crowd.utils.Common;
import org.fu.crowd.vo.AddressVO;
import org.fu.crowd.vo.OrderProjectVO;
import org.fu.crowd.vo.OrderVO;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class OrderController {

    @Resource
    private OrderService orderService;

    @RequestMapping("/order/confirmReturnInfo")
    Common<OrderProjectVO> orderConfirmReturnInfo(@RequestParam("projectId") Integer projectId,
                                                  @RequestParam("returnId")Integer returnId){
        try {
            OrderProjectVO orderProjectVO = orderService.getOrderProjectVO(projectId,returnId);
            return Common.successWithoutData(orderProjectVO);
        }catch (Exception e){
            return Common.failed(e.getMessage());
        }
    }



    @RequestMapping("/get/AddressVO/Remote")
    Common<List<AddressVO>> getAddressVORemote(@RequestParam("memberId")Integer memberId){
        try {
            List<AddressVO> addressVOList = orderService.getAddressVOList(memberId);
            return Common.successWithoutData(addressVOList);
        }catch (Exception e){
            return Common.failed(e.getMessage());
        }
    }



    @RequestMapping("/save/AddressVO/Remote")
    Common<String> saveAddressVORemote(@RequestBody AddressVO addressVO){
        try {
            orderService.saveAddress(addressVO);
            return Common.successWithoutData();
        }catch (Exception e){
            return Common.failed(e.getMessage());
        }
    }



    @RequestMapping("/save/Order/Remote")
    Common<String> saveOrderRemote(@RequestBody OrderVO orderVO){
        try {
            orderService.saveOrder(orderVO);
            return Common.successWithoutData();
        }catch (Exception e){
            return Common.failed(e.getMessage());
        }
    }
}
